﻿function AzureOnlineQueue($initialInfo) {

    var self = this;

    self.name = ko.observable('');

    self.url = ko.observable('');

    self.etag = ko.observable('');

    self.metadata = ko.observableArray([]);
    
    this.setInfo = function ($info) {
        self.name($info.find('Name').text());
        self.url($info.find('Url').text());
        
        var $meta = $info.find('Metadata').children();
        var meta = [];
        for (var i = 0; i < $meta.length; i++) {
            var $metaItem = $($meta[i]);
            var name = $metaItem.prop('tagName');
            var value = $metaItem.text();
            meta.push({
                name: name,
                value: value
            });
        }

        self.metadata(meta);
    };

    if ($initialInfo) {
        this.setInfo($initialInfo);
    }

}

function AzureOnlineQueueMessage($initialInfo) {

    var self = this;

    this.id = ko.observable('');

    this.text = ko.observable('');

    this.dequeueCount = ko.observable(0);

    this.insertionTime = ko.observable(0);

    this.expirationTime = ko.observable(0);

    this.popreceipt = ko.observable();

    this.setInfo = function ($info) {
        self.id($info.find('MessageId').text());
        self.text($info.find('MessageText').text());
        self.dequeueCount($info.find('DequeueCount').text());
        self.insertionTime($info.find('InsertionTime').text());
        self.expirationTime($info.find('ExpirationTime').text());
        self.popreceipt($info.find('PopReceipt').text());
    };

    this.setInfo($initialInfo);

}